<!-- Ajax -->
<script type="text/javascript">
var xmlhttp;
function loadXMLDoc(url,cfunc)
{
	if (window.XMLHttpRequest)
	  {// code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	  }
	else
	  {// code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	xmlhttp.onreadystatechange=cfunc;
	xmlhttp.open("GET",url,true);
	xmlhttp.send();
}
function search()
{
	str = document.getElementById ("keyword").value;
	if (str.length==0)
	{
		return;
	}
	loadXMLDoc("ajax/searchres.php?keyword="+str,function(){
		if (xmlhttp.readyState==4 && xmlhttp.status==200){
		//alert (xmlhttp.responseText);
		document.getElementById("result").innerHTML=xmlhttp.responseText;
		}
	});
}
</script>
<!-- Ajax End -->
		
		<div id="latest-post" class="post">
			<h2 class="title">Welcome to Restaurant Page</h1>
	  		<div class="entry">
				<table width="100%">
                	<tr>
                    	<td align="center">
							<input name="search1" type="text" size="60" id="keyword">&nbsp;
							<input type="button" value="Search" onclick="search()">
						</td>
                    </tr>
                    <tr>
                    	<td align="center">Enter restaurant's name ...</td> 
                    </tr>
                </table>
			</div>
		</div>	
<div id="result">
<?php
include ("include/config.php");	
if (isset($_GET['page'])) { $page  = $_GET['page']; } else { $page=1; }; 
$start_from = ($page-1) * 4; 
$sql = "SELECT * FROM tbl_restaurant LIMIT $start_from,4";
$result = mysql_query("$sql") or die("Invalid query: " . mysql_error());

//print "<table border=\"1\" cellpadding=\"0\">\n";
$i=0;	
while($row=mysql_fetch_array($result)){
	echo '
			<div class="block">
				<a href=""><img src="'.$row['image'].'" width="180" height="126""/></a>
				<div>
					<h3>'.$row['name'].'</h3>
					<a href="http://'.$row['website'].'" target="blank"><h4>'.$row['website'].'</h4></a>
					<p>'.$row['description'].'</p>
					<h4>'.$row['address'].'</h4>
				</div>
			</div>	
	';
}

?>			

<?php 
$sql = "SELECT COUNT(dining_id) FROM tbl_restaurant";
$rs_result = mysql_query($sql); 
$row = mysql_fetch_row($rs_result); 
$total_records = $row[0]; 
$total_pages = ceil($total_records / 4);
for ($i=1; $i<=$total_pages; $i++) { 
			if ($i == $page) {
				print $i.' ';}
			else{
            print '<a style="color: #FF0000" href="index.php?mypage=res&page='.$i.'">'.$i.'</a> '; 
			}
};
mysql_close($link);
?>
</div>
 
